package com.lanou.sfu.songforu.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

import com.lanou.sfu.songforu.R;

import cn.jpush.android.api.JPushInterface;


/**
 * Created by dllo on 15/10/17.
 */
public class WelcomeActivity extends Activity implements Animation.AnimationListener {
    //是否是第一次使用
    private boolean isFirstUse;
    private ImageView imageView = null;
    private Animation alphaAnimation = null;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_layout_welcome);
        Log.i("yinidaoye", "开始---------");
        imageView =(ImageView)findViewById(R.id.welcome_img);
        alphaAnimation = AnimationUtils.loadAnimation(this, R.anim.welcome_alpha);
        alphaAnimation.setFillEnabled(true); //启动Fill保持
        alphaAnimation.setFillAfter(true);  //设置动画的最后一帧是保持在View上面
        imageView.setAnimation(alphaAnimation);
        alphaAnimation.setAnimationListener(this);  //为动画设置监听

    }

    @Override
    protected void onPause() {
        super.onPause();
        JPushInterface.onPause(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        JPushInterface.onResume(this);
    }


    @Override
    public void onAnimationStart(Animation animation) {

    }

    @Override
    public void onAnimationEnd(Animation animation) {

                //读取SharedPreferences中需要的数据
                SharedPreferences preferences = getSharedPreferences("isFirstUse",MODE_WORLD_READABLE);

                isFirstUse = preferences.getBoolean("isFirstUse", true);

                /**
                 *如果用户不是第一次使用则直接调转到显示界面,否则调转到引导界面
                 */
                if (isFirstUse) {

                    startActivity(new Intent(WelcomeActivity.this, GuideActivity.class));
                } else {
                    startActivity(new Intent(WelcomeActivity.this, MainActivity.class));
                }
                finish();

                //实例化Editor对象
                SharedPreferences.Editor editor = preferences.edit();
                //存入数据
                editor.putBoolean("isFirstUse", false);
                //提交修改
                editor.commit();

    }

    @Override
    public void onAnimationRepeat(Animation animation) {

    }
}
